import 'package:flutter/material.dart';
import 'package:proj_shop/pages/webview_page.dart';
import 'package:proj_shop/util/navigator_util.dart';

class LocalNav extends StatefulWidget {
  final List localNavList;

  const LocalNav({Key key, this.localNavList}) : super(key: key);

  @override
  _LocalNavState createState() => _LocalNavState();
}

class _LocalNavState extends State<LocalNav> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 64,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(6),
      ),
      child: Padding(
        padding: const EdgeInsets.all(7.0),
        child: _items(context),
      ),
    );
  }

  Widget _items(BuildContext context) {
    if (widget.localNavList == null) {
      return null;
    }
    List<Widget> list = [];
    widget.localNavList.forEach((element) {
      list.add(_item(context, element));
    });

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: list,
    );
  }

  Widget _item(BuildContext context, String navi) {
    return GestureDetector(
      onTap: () {
        NavigatorUtil.push(
          context,
          WebViewPage(
            title: navi,
            urlString: '',
          ),
        );
      },
      child: Column(
        children: [
          Image.asset(
            navi,
            width: 32,
            height: 32,
            fit: BoxFit.cover,
          ),
          Text('data', style: TextStyle(fontSize: 12)),
        ],
      ),
    );
  }
}
